package com.neuedu.live.ui;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.Socket;
import java.util.Calendar;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import com.neuedu.common.DrawCanvas;
import com.neuedu.live.service.Box;
import com.neuedu.live.service.IStudentUI;
import com.neuedu.live.ui.base.StudentAction;

public class StudentActionPlayer extends StudentAction implements IStudentUI {
	
	BufferedImage buffer = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_RGB);
	Graphics g = buffer.getGraphics();
	DrawCanvas canvas = new DrawCanvas(buffer, DEFAULT_WIDTH, DEFAULT_HEIGHT);
	
	public StudentActionPlayer() {
		canvas.setBounds(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
		this.add(canvas);
	}
	
	public void playImages(Image img) {
		g.drawImage(img, 0, 0, DEFAULT_WIDTH,DEFAULT_HEIGHT,canvas);
		canvas.repaint();
		this.invalidate();
	}

	public static void main(String[] args) {
		new StudentActionPlayer().setVisible(true);
	}

	@Override
	public void msg(String msg) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void playLive(Object data) {
		if(data instanceof Box) {
			Box box = (Box) data;
			byte[] imgData = (byte[]) box.getData();
			ImageIcon icon = new ImageIcon(imgData);
			playImages(icon.getImage());
		}
	}

	@Override
	public void playLiveLink(Box box) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void handDown(Socket socket) {
		// TODO Auto-generated method stub
		
	}

}
